package mygame.TerrainGenerator;
import java.awt.Color;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;


public class HeightMap {

	private byte[][] hmBuffer;
	private int height;
	private int width;
	
	public HeightMap(String fileName){
		
		File f = new File(fileName);
		BufferedImage bf;
		try {
			bf = ImageIO.read(f);
			height = bf.getWidth();
			width = bf.getHeight();
			hmBuffer = new byte[width][height];

			for (int y = 0; y < bf.getWidth(); y++) {
				for (int x = 0; x < bf.getWidth(); x++) {
					Color c = new Color(bf.getRGB(x, y));
					hmBuffer[x][y] = (byte) c.getRed();
					//System.out.print((hmBuffer[x][y] & (0xff)) + " ");
				}
				//System.out.println();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}		
	}
	
	public byte[][] getHeightMapBuffer(){
		return this.hmBuffer;
	}
	
	public short getValue(int x,int y){
		return (short)(this.hmBuffer[x][y] & (0xff));
	}
	
	public int getHeight(){
		return this.height;
	}
	
	public int getWidth(){
		return this.width;
	}
}
